<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="se" uri="http://zc.security/acl"%> 
<c:set var="p" value="${param}"></c:set>
<script type="text/javascript" charset="utf-8" src="<c:url value='/js/plug/ueditor/ueditor.config.js'/>"></script>
<script type="text/javascript" charset="utf-8" src="<c:url value='/js/plug/ueditor/ueditor.all.js'/>"></script>

<div class="easyui-layout" style="width: 100%; height: 100%;" fit="true">
	<div data-options="region:'center',title:'',split:true" style="height: 100%;">
		<form id="form" method="post">
			<table class="detailTable">
				<tr>
					<th style="width: 120px;">信息标题:</th>
					<td colspan="3"><input class="easyui-validatebox" name="newsTitle" data-options="required:true" style="width: 350px;"></td>
				</tr>
				<tr>
					<th>发布时间:</th>
					<td ><input class="easyui-datebox" name="publishDate" id="publishDate" data-options="required:true"></td>
					<th>结束时间(可不填):</th>
					<td ><input class="easyui-datebox" name="endDate" id="endDate" data-options="required:false"></td>
				</tr>
				<tr>
					<th>所属分类:</th>
					<td><select id="newsTypeId" name="newsTypeId" style="width: 150px" data-options="required:true,panelHeight:'auto'">
					</select></td>
					<th>图片:</th>
					<td>
						<span id="smallPicName">
						</span>
						<input type="hidden" id="smallPic" name="smallPic">
						<input type="hidden" id="uploadId" name="uploadId">
						<a class="easyui-linkbutton" href="javascript:uploader();">文件上传</a>
					</td>
				</tr>

				<tr>
					<th>作者:</th>
					<td><input class="easyui-validatebox" name="newsWriter">
					</td>
					<th>来源:</th>
					<td><input class="easyui-validatebox" name="newsSource">
					</td>
				</tr>

				<tr>
					<th>来源地址:</th>
					<td colspan="3"><input class="easyui-validatebox"
						data-options="validType:'url'" name="newsUrl"
						style="width: 350px;"></td>
				</tr>
				<tr>
					<th>内容摘要:</th>
					<td colspan="3"><textarea name="newsBrief" style="width:95%;height:60px;"></textarea></td>
				</tr>
				<tr>
					<th>内容:</th>
					<td colspan="3">
						<textarea name="newsContent" id="newsContent" style="width:100%; height:250px;"></textarea>
					</td>
				</tr>
				<tr>
					<th>点击:</th>
					<td><input class="easyui-numberspinner" name="viewAmount" value="0" style="width: 70px;"></td>
					<th>排序:</th>
					<td><input class="easyui-numberspinner" name="seq" value="0" style="width: 70px;"></td>
				</tr>
				
<!-- 				<tr>
		          <th>信息属性</th>
		          <td colspan="3">
		          	<input name="newsStatus" type="checkbox" value="1" /> 是否发布
		          	<input name="isIndex" type="checkbox" value="1" /> 是否首页
		          	<input name="isCommend" type="checkbox" value="1" /> 是否推荐
		          	<input name="isChannel" type="checkbox" value="1" /> 是否频道
		          	<input name="isScroll" type="checkbox" value="1" /> 是否滚动
		          	<input name="isTop" type="checkbox" value="1" /> 是否置顶
		          </td>
		        </tr> -->
				<tr>
					<td align="right" colspan="4">
						<se:hasPermissions actCode="UPDATE" >
						<input type="button" onclick="submitForm()" class="button" value="提交">
						<input type="button" onclick="pms.resetForm('form')" class="button" value="重置">
						</se:hasPermissions>
					</td>
				</tr>
			</table> 
			<!-- 判断newsID是否为空，如果为空，则是新增，不为空，则是修改  -->
			<%
			    if (request.getParameter("newsId") != null) {
			%>
			<input type="hidden" name="newsId" id="newsId" value="<%=request.getParameter("newsId")%>" />
			<%
			    }
			%>
		</form>
	</div>
</div>

<script type="text/javascript">
var newsId =<%=request.getParameter("newsId")%>;
function  uploader(){
	$.pmsDialog({
		id:"plug_upload",  //固定ID
		title:'选择新闻图片',
		isIf:'true',
		params:{    //这4个必须填   可
    		"fileType":"img", //必填项  file  orimg
    		"oneSelect":'true',
    		"moduleId":"cms",
    		"funcId":"news",
    		"dataId":newsId
    	},
		method:'post',
		href:'<c:url value="/views/jsp/upload/com_uploader_s.jsp"/>',
		width:900,
		height:464
	});
}
function getFiles(obj){
	if(obj!='undefined'){
		$('#smallPicName').html("<img src='"+contentPath+obj[0].relativeFilePath+"small_"+obj[0].fileSysName+"' width='30px;' height='30px;' />");
		$('#smallPic').val(obj[0].relativeFilePath+"small_"+obj[0].fileSysName);
		$('#uploadId').val(obj[0].id);
		alertShow("选择图片成功!");
	}
}
 

$(function() {
var newsTypeId;
newsTypeId = $('#newsTypeId') .combotree({
				url : '<c:url value="/newstype/searchEmBNewsTypeByParentIdToComboTree.do"/>',
				queryParams:{"typeId":<%=request.getParameter("typeId")%>},
				onLoadSuccess:function(){
					if (newsId != null) {
						//更新，获取数据并显示
						var param = {
							"newsId" : newsId
						};
						$.pmsAjax({
							url : '<c:url value="/news/searchEmBNews.do"/>',
							data : param,
							success : function(data) {
								if (data) {
									$('#form').form('load', data);
									UE.getEditor('newsContent',{serverUrl: '<c:url value="/js/plug/ueditor/jsp/controller.jsp"/>',UEDITOR_HOME_URL:'<c:url value="/js/plug/ueditor/"/>'});
									//分类加载
								 
									if(data.smallPic){
										$("#smallPicName").html("<img src='"+contentPath+data.smallPic+"' width='30px;' height='30px;' />");
									}
									
								} else {
									alertError(data.resultMessage);
								}
							}
						});
					} else {
						//新增，设置默认值
						$('#publishDate').val(getDate());
						UE.getEditor('newsContent',{serverUrl: '<c:url value="/js/plug/ueditor/jsp/controller.jsp"/>',UEDITOR_HOME_URL:'<c:url value="/js/plug/ueditor/"/>'});
					}
				}
			});
	});

	function submitForm() {
		if (newsId != null) {
			url = '<c:url value="/news/updateEmBNews.do"/>';
		} else {
			url = '<c:url value="/news/insertNews.do"/>';
		}

		$('#form').form('submit', {
			url : url,
			onSubmit : function(param) {
				if (!$("#form").form('validate')) {
					return false;
				}
			},
			success : function(data) {
				var ret = eval("(" + data + ")");
				if (ret.code=="200") {
					parent.alertShow("数据处理成功");
					parent.tbl.refresh();
					parent.$("#w_form").dialog('close');
				} else {
					alertError(ret.result);
				}
			}
		});
	}

</script>

